package com.dsl.utils;

/**
 * @Description redis工具类（生成key）
 * @Author dsl
 * @Date 2024/9/13 上午11:16
 * @Version 1.0
 */
public class RedisKeyUtil {

    //Redis中的key
    private static final String SPLIT = ":";
    private static final String PREFIX_ENTITY_LIKE = "like:entity";
    private static final String PREFIX_USER_LIKE = "like:user";
    private static final String PREFIX_ATTENTION = "attention";
    private static final String PREFIX_FAN = "fan";
    private static final String PREFIX_KAPTCHA = "kaptcha";
    private static final String PREFIX_TICKET = "ticket";
    private static final String PREFIX_USER = "user";
    private static final String PREFIX_UV = "{uv}";
    private static final String PREFIX_DAU = "{dau}";
    private static final String PREFIX_POST = "post";


    //静态方法，某个实体的赞
    //like:entity:entityType:entityId -> set(userId)
    public static String getEntityLikeKey(int entityType, int entityId) {
        return PREFIX_ENTITY_LIKE + SPLIT + entityType + SPLIT + entityId;
    }

    //某个用户获得的赞
    //like:user:userId -> int
    public static String getUserLikeKey(int userId){
        return PREFIX_USER_LIKE + SPLIT + userId;
    }

    //某个用户关注的实体（用户、帖子、评论）
    //attention:userId:entityType -> zset(entityId, now)
    public static String getAttenetionKey(int userId, int entityType){
        return PREFIX_ATTENTION + SPLIT + userId + SPLIT + entityType;
    }

    //某个实体拥有的粉丝
    //fans:entityType:entityId -> zset(userId,now)
    public static String getFansKey(int entityType, int entityId){
        return PREFIX_FAN + SPLIT + entityType + SPLIT + entityId;
    }

    //登录验证码
    public static String getKaptchaKey(String owner){
        return PREFIX_KAPTCHA + SPLIT + owner;
    }

    //登录凭证
    public static String getTicketKey(String ticket){
        return PREFIX_TICKET + SPLIT + ticket;
    }

    //用户
    public static String getUserKey(int userId){
        return PREFIX_USER + SPLIT + userId;
    }

    // 单日UV的key
    public static String getUVKey(String date) {
        return PREFIX_UV + SPLIT + date;
    }

    // 区间UV的key
    public static String getUVKey(String startDate, String endDate) {
        return PREFIX_UV + SPLIT + startDate + SPLIT + endDate;
    }

    // 单日活跃用户
    public static String getDAUKey(String date) {
        return PREFIX_DAU + SPLIT + date;
    }

    // 区间活跃用户
    public static String getDAUKey(String startDate, String endDate) {
        return PREFIX_DAU + SPLIT + startDate + SPLIT + endDate;
    }

    // 统计帖子分数的key
    public static String getPostScoreKey() {
        return PREFIX_POST + SPLIT + "score";
    }
}
